package at.jsug.topicvoting.gwt1.client.logic.controller;

import at.jsug.topicvoting.gwt1.client.App;
import at.jsug.topicvoting.gwt1.client.logic.IEventListener;
import at.jsug.topicvoting.gwt1.client.logic.event.DeleteVoteEvent;
import at.jsug.topicvoting.gwt1.client.vo.Topic;

public class DeleteVoteCommand implements IEventListener<DeleteVoteEvent> {

	public void eventReceived(DeleteVoteEvent event) {
		System.out.println("DeleteVoteCommand.eventReceived(event="+event+")");
		final Topic topicVote = event.getVoteNotForTopic();
		
		assert(topicVote.isYetVoted() == true);
		
		final Topic updatedTopic = Topic.newNeedTopic(topicVote.getId(), topicVote.getTitle(), topicVote.getVotes() - 1, false);
		App.DATA_FACADE.saveOrUpdateTopic(updatedTopic);
	}

}
